#import "BWBackStitchStorage.h"
#import "BWBackStitch.h"
#import "BWThread.h"


@implementation BWBackStitchStorage

- (id) init
{
    if (self = [super init]) {
        stitches = [[NSMutableArray alloc] init];
    }

    return (self);

} // init


- (void) dealloc
{
    [stitches release];

    [super dealloc];

} // dalloc

- (int) count
{
    return ([stitches count]);
} // count


- (BWBackStitch *) stitchAtIndex: (int) index
{
    return ([stitches objectAtIndex: index]);
} // stitchAtIndex


- (NSArray *) stitches
{
    return (stitches);
} // stitches


- (void) purge
{
    [stitches removeAllObjects];
} // purge


- (void) addBackStitchFromRow: (int) fromRow
                       column: (int) fromColumn
                     quadrant: (BWGrid_Quadrant) fromQuadrant
                        toRow: (int) toRow
                       column: (int) toColumn
                     quadrant: (BWGrid_Quadrant) toQuadrant
                       thread: (BWThread *) thread;
{
    // !!! see if there's already one?

    BWBackStitch *stitch = [[BWBackStitch alloc]
                               initWithStartRow: fromRow
                               startColumn: fromColumn
                               quadrant: fromQuadrant
                               endRow: toRow
                               endColumn: toColumn
                               quadrant: toQuadrant
                               thread: thread];

    [stitches addObject: stitch];
    [stitch release];

} // addBackStitchFromRow


- (void) addStitch: (BWBackStitch *) stitch
{
    [stitches addObject: stitch];
} // addStitch


- (void) removeStitch: (BWBackStitch *) stitch
{
    [stitches removeObject: stitch];
} // removeStitch


- (void) encodeWithCoder: (NSCoder *) coder
{
    [coder encodeObject: stitches];

} // encodeWithCoder


- (id) initWithCoder: (NSCoder *) coder
{
    if (self = [super init]) {
        stitches = [[coder decodeObject] retain];
    }
    
    return (self);

} // initWithCoder


@end // BWBackStitchStorage

